package com.demo.page9101.controller.partner;

import com.demo.common.entity.CooperativePartner;
import com.demo.common.entity.Meta;
import com.demo.page9101.feign.partner.CooperativePartnerFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 合作伙伴
 * 作者：张佑威
 * 分配任务：张改
 * 插入数据：张佑威
 * 接口文档：贾冠博
 */
@RestController
@CrossOrigin
public class CooperativePartnerController {
    Map<String, Object> meta = new HashMap<>();

    Map<String, Object> dates = new HashMap<>();
    @Resource
    private CooperativePartnerFeign cooperativePartnerFeign;

    /**
     * 合作伙伴logo
     * @param industryId
     * @return
     */
    @GetMapping("/Partner/{industryId}")
    public Map selectByIndustryId(@PathVariable("industryId") Integer industryId){
        List<CooperativePartner> cooperativePartners = cooperativePartnerFeign.selectByIndustryId(industryId);

        dates.put("partners",cooperativePartners);
        meta.put("date", dates);
        meta.put("meta", new Meta("获取成功", "200"));
        return meta;
    }
    /**
     * 合作伙伴详情
     * @param id
     * @return
     */
    @GetMapping("/PartnerDetail/{id}")
    public Map selectById(@PathVariable("id") Integer id){
        CooperativePartner cooperativePartner = cooperativePartnerFeign.selectById(id);
        dates.put("partner",cooperativePartner);
        meta.put("date", dates);
        if (cooperativePartner!=null){
            meta.put("meta", new Meta("获取成功", "200"));
        }else {
            meta.put("meta", new Meta("获取失败", "404"));
        }
        return meta;
    }
}
